import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../../environments/environment";
import {Observable} from "rxjs";
import {Instance, InstanceCreate, InstanceUpdate} from "../models/instance";

@Injectable({
  providedIn: 'root'
})
export class InstanceService {

  constructor(private http: HttpClient) { }

  createInstance(data :InstanceCreate): Observable<Instance>{
    return this.http.post<Instance>(`http://${environment.apiServer}/database/instance/`, data)
  }
  deleteInstance(id: string): Observable<string>{
    return this.http.delete<string>(`http://${environment.apiServer}/database/instance/${id}/`)
  }
  updateInstance(data: InstanceUpdate): Observable<Instance>{
    return this.http.put<Instance>(`http://${environment.apiServer}/database/instance/`, data)
  }
  listInstance(): Observable<Array<Instance>>{
    return this.http.get<Array<Instance>>(`http://${environment.apiServer}/database/instances/`)
  }

}
